﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CLVisionModbusTS
{
    [Serializable]
    internal class CustomerNode
    {
        public CustomerNode(string text)
        {
            _text = text;
            _fullPath = text;
        }
        List<CustomerNode> _nodes = new List<CustomerNode>();

        string _fullPath;
        int _objectID = -1;
        string _text;
        private CustomerNode _parent;



        public List<CustomerNode> Nodes { get => _nodes; set => _nodes = value; }
        public string FullPath { get => _fullPath; set => _fullPath = value; }
        public int ObjectID { get => _objectID; set => _objectID = value; }
        public string Text { get => _text; set => _text = value; }
        public CustomerNode Parent { get => _parent; set => _parent = value; }

   

        public void Add(CustomerNode childTreeNode)
        {
            //当前节点的FullPath
            childTreeNode.FullPath = Path.Combine(this._fullPath, childTreeNode._text);
            _nodes.Add(childTreeNode);
            childTreeNode.Parent = this;

            //递归  修改子节点的FullPath
            ModifyFullPath(childTreeNode._nodes);
        }
        public void ModifyFullPath(List<CustomerNode> treeNodeCustomer)
        {
            foreach (var item in treeNodeCustomer)
            {
                item.FullPath = Path.Combine(item.Parent.FullPath, item._text);
                ModifyFullPath(item._nodes);
            }
        }
    }
}
